package org.neuedu.controller;

import jakarta.annotation.Resource;
import org.neuedu.common.ResultJson;
import org.neuedu.entity.Prescription;
import org.neuedu.service.PrescriptionService;
import org.neuedu.service.RegisterService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lzw
 * @since 2024-11-19
 */
@RestController
@RequestMapping("/prescription")
public class PrescriptionController {
    @Resource
    PrescriptionService prescriptionService;
    @Resource
    RegisterService registerService;
    @PostMapping("/add")
    ResultJson<Boolean> add(String content) {
        return ResultJson.success(prescriptionService.add(content), "开设处方成功");
    }
    @GetMapping("/fayao")
    ResultJson<?> fayao(String caseNumber) {
        Map<String, Object> map = new HashMap<>();
        map.put("register", registerService.getByCaseNumber(caseNumber));
        map.put("drugList", prescriptionService.fayao(caseNumber));
        return ResultJson.success(map);
    }
    @GetMapping("/jiaofei")
    ResultJson<List<Prescription>> jiaofei (String caseNumber, String checkState) {
        return ResultJson.success(prescriptionService.jiaofei(caseNumber, checkState));
    }
    @PostMapping("/updateState")
    ResultJson<Boolean> updateState(Integer[] ids) {
        return ResultJson.success(prescriptionService.updateState(ids));
    }
    @PostMapping("/update")
    ResultJson<Boolean> update(Integer id,Integer drugId,Integer drugNumber) {
        String check= prescriptionService.update(id,drugId,drugNumber);
        if (check.equals("开药成功")){
            return ResultJson.success(true,check);
        }else{
            return ResultJson.failed(check);
        }
    }
    @PostMapping("/backMedical")
    ResultJson<Boolean> backMedical(Integer id) {
        return ResultJson.success(prescriptionService.backMedical(id),"退药成功");
    }

}
